home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / eiffel / smalleif.97 / se.t / SmallEiffel / lib_std / numeric.e < prev    next >
Encoding:
Text File  |  1996-05-02  |  2.0 KB  |  104 lines

  1. -- Part of SmallEiffel -- Read DISCLAIMER file -- Copyright (C) 
  2. -- Dominique COLNET and Suzanne COLLIN -- colnet@loria.fr
  3. --
  4. deferred class  NUMERIC
  5. --
  6. -- This class describes a ring.
  7. --
  8.    
  9. inherit ANY undefine is_equal end;
  10.    
  11. feature {ANY} 
  12.  
  13.    infix "+" (other : like Current) : like Current is
  14.      -- Sum of 'Current' and 'other'.
  15.       require
  16.      other /= Void
  17.       deferred
  18.       end;
  19.    
  20.    infix "-" (other : like Current) : like Current is
  21.      -- Difference of 'Current' and 'other'.
  22.       require
  23.      other /= Void
  24.       deferred
  25.       end;
  26.  
  27.    infix "*" (other : like Current) : like Current is
  28.      -- Product of 'Current' and 'other'.
  29.       require
  30.      other /= Void
  31.       deferred
  32.       end;
  33.    
  34.    infix "/" (other: like Current): NUMERIC is
  35.      -- Quotient of 'Current' and 'other'.
  36.       require
  37.      other /= Void;
  38.      valid_divisor (other)
  39.       deferred
  40.       end;
  41.  
  42.    infix "^" (exp : INTEGER) : like Current is
  43.      -- 'Current' raised to 'exp'-th power.
  44.       require
  45.      exp >= 0 
  46.       local
  47.      e       : INTEGER;
  48.      product : like Current;
  49.      factor  : like Current;
  50.       do
  51.      product := one;
  52.      factor  := Current;
  53.      from
  54.         e := exp;
  55.      until
  56.         e = 0
  57.      loop
  58.         if (e \\ 2) = 1 then
  59.            product := product * factor
  60.         end;
  61.         e := e // 2;
  62.         factor := factor * factor;
  63.      end;
  64.      Result := product;
  65.       end;
  66.  
  67.    prefix "+" : like Current is
  68.      -- Unary plus of 'Current'.
  69.       do
  70.      Result := Current
  71.       end;
  72.  
  73.    prefix "-" : like Current is
  74.      -- Negative of 'Current'.
  75.       do
  76.      Result := zero - Current
  77.       end;
  78.  
  79.    valid_divisor(other: like Current) : BOOLEAN is
  80.      -- Is 'other' a valid divisor for 'Current'?
  81.       require
  82.      other /= Void
  83.       deferred
  84.       end;
  85.  
  86.    one : like Current is
  87.      -- The neutral element of multiplication.
  88.       deferred
  89.       ensure
  90.      neutral_element : -- Result is the neutral element of 
  91.      -- multiplication.
  92.       end;
  93.  
  94.    zero: like Current is
  95.      -- The neutral element of addition.
  96.       deferred
  97.       ensure
  98.      neutral_element : -- Result is the neutral element of 
  99.      -- addition.
  100.       end;
  101.    
  102. end -- class NUMERIC
  103.  
  104.